import {compute} from "../utils/utils";

function calculator(data) {
    function setNumber(type, val) {
        if (typeof (val) !== "number") {
            val = Number(val);
        }
        data[type] = val;
        return compute(
            data.curMethod,
            data.oneNumber,
            data.twoNumber
        )
    }

    function changeMethod(method) {
        data.curMethod = method;
        return compute(
            data.curMethod,
            data.oneNumber,
            data.twoNumber
        )
    }

    return {
        setNumber,
        changeMethod
    }
}

export default calculator;
